<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

const form = ref({ username: '', password: '' })
const loading = ref(false)
const remember = ref(true)
const router = useRouter()

function handleLogin() {
  if (!form.value.username || !form.value.password) {
    ElMessage.warning('请输入用户名和密码')
    return
  }
  loading.value = true
  setTimeout(() => {
    loading.value = false
    if (form.value.username === 'admin' && form.value.password === '123456') {
      ElMessage.success('登录成功')
      router.push('/')
    } else {
      ElMessage.error('用户名或密码错误')
    }
  }, 1000)
}
</script>

<template>
  <div class="login-wrapper">
    <div class="login-left">
      <div class="login-logo">
        <img src="../../assets/images/login-illustration.svg" alt="logo" />
        <span>Medical-Admin</span>
      </div>
      <div class="login-illustration">
        <img src="@/assets/images/login-illustration.svg" alt="illustration" />
      </div>
    </div>
    <div class="login-right">
      <div class="login-form-card">
        <div class="login-title">欢迎回来 <span class="wave">👋</span></div>
        <div class="login-subtitle">请输入您的账户信息以开始管理您的项目</div>
        <el-form :model="form" @keyup.enter="handleLogin">
          <el-form-item>
            <el-input v-model="form.username" placeholder="用户名" clearable />
          </el-form-item>
          <el-form-item>
            <el-input v-model="form.password" type="password" placeholder="密码" clearable show-password />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="width:100%" :loading="loading" @click="handleLogin">登录</el-button>
          </el-form-item>
        </el-form>
        <div class="login-copyright">
          Copyright © 2024 Medical-Admin
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.login-wrapper {
  display: flex;
  min-height: 100vh;
}

.login-left {
  flex: 1.2;
  background: linear-gradient(135deg, #f8fafc 0%, #e0e7ef 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
}

.login-logo {
  display: flex;
  align-items: center;
  font-size: 26px;
  font-weight: bold;
  margin-bottom: 32px;
  color: #333;
}

.login-logo img {
  width: 48px;
  margin-right: 12px;
}

.login-illustration img {
  width: 320px;
  max-width: 90vw;
  margin-bottom: 32px;
}

.login-desc {
  text-align: center;
}

.login-desc-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 8px;
}

.login-desc-sub {
  color: #888;
  font-size: 14px;
}

.login-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.login-form-card {
  width: 350px;
  padding: 40px 32px 24px 32px;
  box-shadow: 0 2px 24px 0 rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.login-title {
  text-align: left;
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 8px;
}

.login-subtitle {
  color: #888;
  font-size: 14px;
  margin-bottom: 24px;
}

.wave {
  display: inline-block;
  animation: wave 1.5s infinite;
}

@keyframes wave {
  0% {
    transform: rotate(0deg);
  }

  10% {
    transform: rotate(14deg);
  }

  20% {
    transform: rotate(-8deg);
  }

  30% {
    transform: rotate(14deg);
  }

  40% {
    transform: rotate(-4deg);
  }

  50% {
    transform: rotate(10deg);
  }

  60% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(0deg);
  }
}

.login-forgot {
  float: right;
  color: #409eff;
  font-size: 13px;
  text-decoration: none;
  margin-left: auto;
}

.login-other {
  margin: 16px 0 8px 0;
  color: #888;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-create {
  text-align: center;
  font-size: 13px;
  margin-bottom: 8px;
}

.login-create a {
  color: #409eff;
  text-decoration: none;
}

.login-copyright {
  text-align: center;
  color: #bbb;
  font-size: 12px;
  margin-top: 8px;
}
</style>